extends Node

var consts
var path
var base
var lv4 = []
var osName

func _init():
	call_deferred("Init")

func Init():
	if globalData.infoDs.has("g_ZHPBase"):
		base = globalData.infoDs["g_ZHPBase"]
	if base != null:
		path = chaData.infoDs["cex___zahuopu-Hide"].dir
		osName = OS.get_name()

#左半场单元格
const cellsLeft = [
	Vector2(0,0), Vector2(0,1), Vector2(0,2), Vector2(0,3), Vector2(0,4), Vector2(0,5),

	Vector2(1,0), Vector2(1,1), Vector2(1,2), Vector2(1,3), Vector2(1,4), Vector2(1,5), 
	
	Vector2(2,0), Vector2(2,1), Vector2(2,2), Vector2(2,3), Vector2(2,4), Vector2(2,5), 
	
	Vector2(3,0), Vector2(3,1), Vector2(3,2), Vector2(3,3), Vector2(3,4), Vector2(3,5), 
	
	Vector2(4,0), Vector2(4,1), Vector2(4,2), Vector2(4,3), Vector2(4,4), Vector2(4,5)
]
#右半场单元格
const cellsRight = [
	Vector2(9,0), Vector2(9,1), Vector2(9,2), Vector2(9,3), Vector2(9,4), Vector2(9,5),

	Vector2(8,0), Vector2(8,1), Vector2(8,2), Vector2(8,3), Vector2(8,4), Vector2(8,5), 
	
	Vector2(7,0), Vector2(7,1), Vector2(7,2), Vector2(7,3), Vector2(7,4), Vector2(7,5),
	
	Vector2(6,0), Vector2(6,1), Vector2(6,2), Vector2(6,3), Vector2(6,4), Vector2(6,5), 
	
	Vector2(5,0), Vector2(5,1), Vector2(5,2), Vector2(5,3), Vector2(5,4), Vector2(5,5)
]

func getAllCells(team):
	if team == 1:
		return cellsLeft + cellsRight
	elif team == 2:
		return cellsRight + cellsLeft

#当前是否是移动端
func isMobile():
	return osName == "Android"

#角色是否在场上
func inBattle(cha):
	return sys.main.matCha(cha.get("cell")) == cha

#从当前池子中获得随机物品
func getRndItem():
	return sys.newItem(itemData.rndPool.rndItem().id)

#根据配置创建按钮
func createButton(id, baseNode, obj):
	var config = consts.buttonConfig.get(id)
	var btn = Button.new()
	btn.text = config.text
	if config.has("margin_left"):
		btn.margin_left = config.margin_left
	if config.has("margin_right"):
		btn.margin_right = config.margin_right
	if config.has("margin_top"):
		btn.margin_top = config.margin_top
	if config.has("position"):
		btn.rect_position = config.position
		
	if not config.has("args"):
		config["args"] = []

	if config.has("shortCut"):
		var sc = ShortCut.new()
		var key = InputEventKey.new() 
		key.scancode = config.shortCut
		sc.set_shortcut(key)
		btn.shortcut = sc
		btn.shortcut_in_tooltip = true
		
	btn.connect("pressed", obj, config.conn, config.args)
	baseNode.add_child(btn)
	return btn
	
#根据参数创建按钮
func createItemButton(baseNode, bindInstance, text, callback, args=[], position = Vector2(90, 170)):
	var b = Button.new()
	b.rect_position = position
	b.text = text
	b.connect("pressed", bindInstance, callback, args)
	baseNode.add_child(b)
	return b

func createLabel(text, baseNode):
	var lb = Label.new()
	lb.text = text
	baseNode.add_child(lb)
	return lb

func createRichTextLabel(text, baseNode, size = Vector2(580, 50)):
	var lb = RichTextLabel.new()
	lb.bbcode_text = text
	lb.bbcode_enabled = true
	lb.push_align(0)
	lb.set_custom_minimum_size(size)
	lb.name = "RichTextLabel"
	baseNode.add_child(lb)
	return lb

#创建图片
func createPicture(file):
	return base.loadImg(path, file)

#创建窗口
func createWindowDialog(baseNode, title, size = Vector2(900, 500)):
	var window = WindowDialog.new()
	window.set_size(size)
	window.window_title = title
	baseNode.add_child(window)
	return window

func createVBox(baseNode):
	var itemBox = VBoxContainer.new()
	baseNode.add_child(itemBox)
	return itemBox